package com.deer.wms.ware.task.strategy;

import cn.hutool.core.util.ObjectUtil;
import com.deer.wms.ware.task.model.SO.SoDetail;
import com.deer.wms.ware.task.model.Wave.WaveDetail;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: xu
 * @Date: 2022/07/27/16:03
 * @Description:
 */
@Component
public class SoDetailStrategy implements ApplicationContextAware {
    private Map<Integer, DetailStrategy> iFileStrategyMap = new ConcurrentHashMap<>();
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, DetailStrategy> beansOfType = applicationContext.getBeansOfType(DetailStrategy.class);
        //根据类型获取
        beansOfType.values().forEach(soDetail -> iFileStrategyMap.put(soDetail.getState(), soDetail));
    }

    public void resolveSoDetail(SoDetail oldSoDetail, SoDetail newDetail, WaveDetail waveDetail,String waveCode) {


        DetailStrategy detailStrategy = iFileStrategyMap.get(waveDetail.getState());
        if (ObjectUtil.isNotEmpty(detailStrategy)) {
            detailStrategy.allocation(oldSoDetail, newDetail, waveCode);
        }
    }

}
